#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
void Child()
{
    int cnt=5;
    while(cnt)
    {
        printf("I am child pid=%d ppid=%d cnt=%d\n",getpid(),getppid(),cnt);
        sleep(1);
        cnt--;
    }
}

int main()
{
    pid_t pid=fork();
    if(pid==0)
    {
        Child();
        exit(11);
    }
    if(pid>0)
    {    
        printf("I am child pid=%d ppid=%d\n",getpid(),getppid());
    }

    sleep(8);
    int status=0;
    pid_t ret=waitpid(pid,&status,0);
    if(ret==pid)
    {
        printf("waitpid success ret=%d\n",ret);
        if(WIFEXITED(status))
        {
            printf("进程是正常跑完的->signal:%d,waitcode:%d\n",status&0x7F,(status)>>8&0xFF);
            
           // printf("signal:%d,waitcode:%d\n",WIFEXITED(status),WEXITSTATUS(status));
        }
        else{
            printf("进程出异常了\n");
        }
    }

    sleep(5);
    return 0;
}
